home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 15 / macformat_15.iso / C de cerca / Codewarrior Lite / MacOS Support / Headers / ANSI Headers / streambuf < prev    next >
Text File  |  1995-12-29  |  5KB  |  164 lines

  1. // streambuf standard header
  2. #ifndef _STREAMBUF_
  3. #define _STREAMBUF_
  4. #include <ios>
  5.  
  6. #if __MWERKS__
  7. #pragma options align=mac68k
  8.  
  9. #if __CFM68K__ && __USING_IMPORTED_ANSI__
  10. #pragma import on
  11. #endif
  12. #endif
  13.  
  14.         // macros
  15. #define EOF    (-1)
  16.         // type streamoff
  17. typedef long streamoff;
  18. const streamoff _BADOFF = -1;
  19.         // class streampos
  20. class streampos {
  21. public:
  22.     streampos(streamoff = 0, const _Fpost * = 0);
  23.     streamoff offset() const;
  24.     streamoff operator-(const streampos&) const;
  25.     streampos& operator+=(streamoff _O)
  26.         {_Pos += _O; return (*this); }
  27.     streampos& operator-=(streamoff _O)
  28.         {_Pos -= _O; return (*this); }
  29.     streampos operator+(streamoff _O) const
  30.         {streampos s = *this; s += _O; return s; }
  31.     streampos operator-(streamoff _O) const
  32.         {streampos s = *this; s -= _O; return s; }
  33.     _Bool operator==(const streampos&) const;
  34.     _Bool operator!=(const streampos& _R) const
  35.         {return (!(*this == _R)); }
  36.     _Fpost *_Fpos()
  37.         {return (&_Fp); }
  38. private:
  39.     streamoff _Pos;
  40.     _Fpost _Fp;
  41.     };
  42.         // class streambuf
  43. class streambuf {
  44. public:
  45.     virtual ~streambuf();
  46.     virtual int showmany();
  47.     streampos pubseekoff(streamoff _O, ios::seekdir _W,
  48.         ios::openmode _M = ios::in | ios::out)
  49.         {return (seekoff(_O, _W, _M)); }
  50.     streampos pubseekoff(streamoff _O, ios::seek_dir _W,
  51.         ios::open_mode _M)
  52.         {return (pubseekoff(_O, (ios::seekdir)_W, (ios::openmode)_M)); }
  53.     streampos pubseekpos(streampos _P,
  54.         ios::openmode _M = ios::in | ios::out)
  55.         {return (seekpos(_P, _M)); }
  56.     streampos pubseekpos(streampos _P, ios::open_mode _M)
  57.         {return (seekpos(_P, (ios::openmode)_M)); }
  58.     streambuf *pubsetbuf(char *_S, int _N)
  59.         {return (setbuf(_S, _N)); }
  60.     int pubsync()
  61.         {return (sync()); }
  62.     int sbumpc()
  63.         {return (gptr() != 0 && gptr() < egptr()
  64.             ? *_Gn()++ : uflow()); }
  65.     int sgetc()
  66.         {return (gptr() != 0 && gptr() < egptr()
  67.             ? *_Gn() : underflow()); }
  68.     int sgetn(char *_S, int _N)
  69.         {return (xsgetn(_S, _N)); }
  70.     int snextc()
  71.         {return (sbumpc() == EOF ? EOF : sgetc()); }
  72.     int sputbackc(char _C)
  73.         {return (gptr() != 0 && eback() < gptr()
  74.             && _C == gptr()[-1]
  75.             ? *--_Gn() : pbackfail((unsigned char)_C)); }
  76.     int sungetc()
  77.         {return (gptr() != 0 && eback() < gptr()
  78.             ? *--_Gn() : pbackfail()); }
  79.     int sputc(int _C)
  80.         {return (pptr() != 0 && pptr() < epptr()
  81.             ? (*_Pn()++ = _C) : overflow(_C)); }
  82.     int sputn(const char *_S, int _N)
  83.         {return (xsputn(_S, _N)); }
  84.     int in_avail()
  85.         {return (gptr() != 0 && gptr() < egptr()
  86.             ? egptr() - gptr() : showmany()); }
  87. protected:
  88.     streambuf()
  89.         {_Init(); }
  90.     streambuf(ios::_Uninitialized)
  91.         {}
  92.     char *eback() const
  93.         {return (*_IGbeg); }
  94.     char *gptr() const
  95.         {return (*_IGnext); }
  96.     char *egptr() const
  97.         {return (*_IGend); }
  98.     void gbump(int _N)
  99.         {*_IGnext += _N; }
  100.     void setg(char *_B, char *_N, char *_E)
  101.         {*_IGbeg = _B, *_IGnext = _N, *_IGend = _E; }
  102.     char *pbase() const
  103.         {return (*_IPbeg); }
  104.     char *pptr() const
  105.         {return (*_IPnext); }
  106.     char *epptr() const
  107.         {return (*_IPend); }
  108.     void pbump(int _N)
  109.         {*_IPnext += _N; }
  110.     void setp(char *_B, char *_E)
  111.         {*_IPbeg = _B, *_IPnext = _B, *_IPend = _E; }
  112.     void setp(char *_B, char *_N, char *_E)
  113.         {*_IPbeg = _B, *_IPnext = _N, *_IPend = _E; }
  114.     unsigned char *&_Gn()
  115.         {return ((unsigned char *&)*_IGnext); }
  116.     unsigned char *&_Pn()
  117.         {return ((unsigned char *&)*_IPnext); }
  118.     virtual int overflow(int = EOF);
  119.     virtual int pbackfail(int = EOF);
  120.     virtual int underflow();
  121.     virtual int uflow();
  122.     virtual int xsgetn(char *, int);
  123.     virtual int xsputn(const char *, int);
  124.     virtual streampos seekoff(streamoff, ios::seekdir,
  125.         ios::openmode = ios::in | ios::out);
  126.     virtual streampos seekpos(streampos,
  127.         ios::openmode = ios::in | ios::out);
  128.     virtual streambuf *setbuf(char *, int);
  129.     virtual int sync();
  130.     void _Init();
  131.     void _Init(char **, char **, char **, char **, char **,
  132.         char **);
  133. private:
  134.     streambuf(const streambuf&); // undefined
  135.     streambuf& operator=(const streambuf&); // undefined
  136.     char *_Gbeg, *_Gnext, *_Gend;
  137.     char *_Pbeg, *_Pnext, *_Pend;
  138.     char **_IGbeg, **_IGnext, **_IGend;
  139.     char **_IPbeg, **_IPnext, **_IPend;
  140.     };
  141.  
  142. #if __MWERKS__
  143. #if __CFM68K__ && __USING_IMPORTED_ANSI__
  144. #pragma import reset
  145. #endif
  146.  
  147. #pragma options align=reset
  148. #endif
  149.  
  150. #endif
  151.  
  152. /*
  153.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  154.  * Consult your license regarding permissions and restrictions.
  155.  */
  156.  
  157. /* Change log:
  158.  *94June04 PlumHall baseline
  159.  *94Sept30 Applied diffs for Fri Aug 26 00:51:20 1994
  160.  *94Sept30 Applied diffs for Tue Aug 30 07:28:05 1994
  161.  *94Oct07 Inserted MW changes
  162.  *94Dec27mm Added in_avail following pjp.
  163.  */
  164.